//logs.js
//获取应用实例
const app = getApp();
Page({
  data: {
    dataList: [
      {"id":1,"name":"理工类","checked":true,"data":[
        {"id":10001,"name":"北京大学"},
        {"id":10002,"name":"中国人民大学"},
        {"id":10003,"name":"清华大学"},
        {"id":80201,"name":"院大学"},
        {"id":10202,"name":"中s学"},
        {"id":10203,"name":"sheji"},
        {"id":80201,"name":"hello"}]
      },
      {"id":2,"name":"文学类","data":[
        {"id":10001,"name":"北学"},
        {"id":10002,"name":"中国"},
        {"id":10003,"name":"清华大学"},
        {"id":10052,"name":"中国"},
        {"id":10503,"name":"清华大学"},
        {"id":80501,"name":"中国院大学"}]
      },
      {"id":3,"name":"办公类","data":[
        {"id":10001,"name":"北学"},
        {"id":10002,"name":"中国"},
        {"id":10003,"name":"清华大学"},
        {"id":80001,"name":"中国院大学"}]
      }
    ],
    skills: {},
    skillType:'good',
    load:true
  },
  onLoad: function (option) {
    this.setData({
      skillType:option.type
    })
    //console.log(this.data.school[this.data.selectId])

  },

  onReady:function(){
  },
  submitSkills(e) {
    let items = this.data.dataList;
    let choose=[];
    for(let ite in items){
      let tags = items[ite].data;
      for(let t in tags){
        let tag = tags[t];
        if(tag.checked){
            choose.push({
              pid:items[ite].id,
              id:tag.id,
              name:tag.name
            })
        }
      }
    }
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2]; //上一个页面
    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    let ob = this.data.skillType=='good' ? {
      skills_good: choose
    } : {
      skills_know: choose
    }
    prevPage.setData(Object.assign(ob,{editType:this.data.skillType}))
    wx.navigateBack({//返回
      delta: 1
    })
  },
  //选择tag
  chooseCheckbox(e) {
    let items = this.data.dataList;
    let dataset =  e.currentTarget.dataset;
    let index = dataset.pind;
    let changeItem = items[index].data;
    let values = dataset.id;
    changeItem.map((item)=>{
      if(item.id==values){
        item.checked = !item.checked;
      }
      return item;
    })
    items[index].data=changeItem;
    this.setData({
      dataList: items
    })
  },
  //点击title
  chooseCheckTitle:function(e){
    let items = this.data.dataList;
    let dataset =  e.currentTarget.dataset;
    let index = dataset.index;
    console.log(items[index])
    items[index].checked = !items[index].checked;
    this.setData({
      dataList: items
    })
  }

})
